package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.InvoiceDAO;
import entity.Invoice;

@WebServlet("/addinvoice")
public class  AddInvoiceServlet extends HttpServlet {
	private InvoiceDAO invoicedao = new InvoiceDAO();
	private String action;

	public AddInvoiceServlet() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		Invoice_add(request);
		request.getRequestDispatcher("/invoiceList.jsp").forward(request, response);
	}

	private void Invoice_add(HttpServletRequest request) {
		try {
			Invoice fp=new Invoice();
			fp.setPno(request.getParameter("pno"));
			fp.setCno(request.getParameter("cno"));;
			fp.setPaystate(request.getParameter("paystate"));
			fp.setPaytimeno(request.getParameter("paytimeno"));
			fp.setPprice(request.getParameter("pprice"));
			fp.setPtime(request.getParameter("ptime"));
			this.invoicedao.addInvoice(fp);
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
		
	}
}
